import {BaseChecker, CheckerRet} from "./BaseChecker";
import {CellData} from "../CellData";
import {ConfigDataEntity} from "../../generate/entitas";
import {PlatForm} from "../PlatForm";

export class ComplexChecker extends BaseChecker{
	check(cell: CellData, columnEntity: ConfigDataEntity, platForm: PlatForm): CheckerRet {
		let temp = []
		for (let i = 0; i < this.checkerList.length; i+=2) {
			let checker = this.checkerList[i]
			let type = this.checkerList[i + 1]
			let ret = checker.check(cell, columnEntity, platForm)
			temp.push(ret)
			temp.push(type)
		}
		let bRet = temp[0].ret
		let error = temp[0].error
		for (let i = 2; i < temp.length; i+= 2) {
			let type = temp[i + 2]
			if (type == 0){
				bRet = bRet && temp[i].ret
				if(!bRet){
					error = temp[i].err
				}
			}else if (type == 1){
				bRet = bRet || temp[i]
				if (!bRet ){
					error = temp[i].err
				}
			}
		}
		let retData = new CheckerRet()
		retData.ret = bRet
		retData.error = error
		return retData
	}
}